package com.atguigu.demo01_mybatisplus.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MpConfig {
    //mp的拦截器：
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        //创建mp拦截器对象
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();

        //创建mp-内置-分页拦截器
        PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor(DbType.MYSQL);
        //将内置 分页拦截器设置给mp拦截器
        interceptor.addInnerInterceptor(paginationInnerInterceptor);

        // 将mp拦截器返回注入到ioc容器中
        return interceptor;
    }
}
